<extend name="public/form"/>
<block name="css"></block>
<block name="content">
    <div class="layui-card-header ">
        <span class="layui-breadcrumb">
          <a href="/admin" target="_blank">首页</a>
          <a href="javascript:;">采集管理</a>
          <a href="javascript:;" onclick="parent.xadmin.add_tab('采集任务管理','{:url('index')}')">采集任务管理</a>
          <a><cite>添加采集详情</cite></a>
        </span>
        <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right"
           href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh-3" style="line-height:30px"></i></a>
    </div>
    <div class="layui-card-body layui-tab"><!--选项卡父容器必须包含layui-tab class-->
        <ul class="layui-tab-title">
            <li class="layui-this">简单任务</li>
            <li>顺序自增任务</li>
            <li>列表再采集</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form id="form1" class="layui-form">
                    <input type="hidden" name="type" value="1">
                    <div class="layui-form-item">
                        <label class="layui-form-label">采集任务名</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" lay-verify="required" lay-reqtext="请输入采集任务名"
                                   placeholder="请输入采集任务名"
                                   autocomplete="off" class="layui-input ">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">绑定采集规则</label>
                        <div class="layui-input-block">
                            <select name="collect_rule_id" lay-verify="required" lay-reqtext="请绑定采集规则" lay-search=""search>
                                <option value=""></option>
                                <foreach $collectRules as $vo>
                                    <option value="{$vo.id}">{$vo.name}</option>
                                </foreach>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">采集链接列表</label>
                        <div class="layui-input-block">
                            <textarea name="urls" placeholder="请输入采集链接,多个链接使用换行逗号或竖杠分隔" class="layui-textarea"
                                      lay-verify="required" lay-reqtext="请输入采集任务名"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" lay-submit="" lay-filter="submit_table1">立即提交
                            </button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>

            </div>
            <div class="layui-tab-item">
                <form id="form2" class="layui-form">
                    <input type="hidden" name="type" value="2">
                    <div class="layui-form-item">
                        <label class="layui-form-label">采集任务名</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" lay-verify="required" lay-reqtext="请输入采集任务名"
                                   placeholder="请输入采集任务名"
                                   autocomplete="off" class="layui-input ">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">绑定采集规则</label>
                        <div class="layui-input-block">
                            <select name="collect_rule_id" lay-verify="required" lay-reqtext="请绑定采集规则" lay-search=""search>
                                <option value=""></option>
                                <foreach $collectRules as $vo>
                                    <option value="{$vo.id}">{$vo.name}</option>
                                </foreach>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">匹配链接</label>
                        <div class="layui-input-block">
                            <input type="text" name="matching" lay-verify="required" placeholder="请输入通用链接,使用{i}替换自增长的数字"
                                   autocomplete="off" class="layui-input ">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">开始值</label>
                        <div class="layui-input-block">
                            <input type="text" name="matching_start" lay-verify="required|number" placeholder="请输入开始值"
                                   autocomplete="off" class="layui-input ">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">结束值</label>
                        <div class="layui-input-block">
                            <input type="text" name="matching_end" lay-verify="required|number" placeholder="请输入结束值"
                                   autocomplete="off" class="layui-input ">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" lay-submit="" lay-filter="submit_table2">立即提交
                            </button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
            <div class="layui-tab-item">
                <form id="form3" class="layui-form">
                    <input type="hidden" name="type" value="3">
                    <div class="layui-form-item">
                        <label class="layui-form-label">采集任务名</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" lay-verify="required" lay-reqtext="请输入采集任务名"
                                   placeholder="请输入采集任务名"
                                   autocomplete="off" class="layui-input ">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">绑定采集规则</label>
                        <div class="layui-input-block">
                            <select name="collect_rule_id" lay-verify="required" lay-reqtext="请绑定采集规则" lay-search=""search>
                                <option value=""></option>
                                <foreach $collectRules as $vo>
                                    <option value="{$vo.id}">{$vo.name}</option>
                                </foreach>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">任务列表</label>
                        <div class="layui-input-block">
                            <select name="matching_start" lay-verify="required" lay-reqtext="请选择已经采集完成的任务列表" lay-search=""search>
                                <option value=""></option>
                                <foreach $collectTasks as $vo>
                                    <option value="{$vo.id}">{$vo.name}</option>
                                </foreach>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">属性key</label>
                        <div class="layui-input-block">
                            <input type="text" name="matching" lay-verify="required" placeholder="请输入已成功采集的属性key"
                                   autocomplete="off" class="layui-input ">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" lay-submit="" lay-filter="submit_table3">立即提交
                            </button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</block>
<block name="js">
    <script>
        layui.use(['jquery', 'form', 'layer', 'element', 'table'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                layer = layui.layer;
            layui.element.render();

            form.on('submit(submit_table1)', function (data) {
                send_post(data,"type1");
                return false;
            });
            form.on('submit(submit_table2)', function (data) {
                send_post(data,"type2");
                return false;
            });
            form.on('submit(submit_table3)', function (data) {
                send_post(data,"type3");
                return false;
            });
            function send_post(data,type){
                let send_json = data.field;
                $.ajax({
                    url: '/admin/collect_task/add_'+type,
                    method: 'post',
                    data: send_json,
                    success: function (res) {
                        if (res.code == 0) {
                            layer.alert("增加成功", {
                                icon: 6
                            }, function () {
                                location.reload();
                            });
                        } else {
                            layer.msg(res.msg, {icon: 5});
                        }
                    },
                    error: function (data) {
                        layer.msg('服务器繁忙', {icon: 5});
                    }
                });
            }
        })
    </script>
</block>